/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import org.apache.log4j.*;
import org.apache.log4j.xml.DOMConfigurator;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.support.PagedListHolder;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import service.UsuarioService;

/**
 *
 * @author Fátima Pestana
 */
public class IndexUsuarioController implements Controller {

    private UsuarioService usuarioService;
    private static Logger loggers = null;

    public void setClienteService(UsuarioService usuarioService) {
        this.usuarioService = usuarioService;
    }

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map model = new HashMap();
        PagedListHolder pagedListHolder = (PagedListHolder) request.getSession().getAttribute("usuarioList");
        System.out.println("");
        if (pagedListHolder == null) {
            pagedListHolder = new PagedListHolder(usuarioService.getUsuarioList());
        } else {
            String page = (String) request.getParameter("page");
            if ("next".equals(page)) {
                pagedListHolder.nextPage();
            } else if ("previous".equals(page)) {
                pagedListHolder.previousPage();
            }
        }

        request.getSession().setAttribute("usuarioList", pagedListHolder);
        model.put("usuarioList", pagedListHolder);
        return new ModelAndView("misClientes", model);
    }
}
